package com.dfs.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dfs.entity.Fruit;
import com.dfs.service.FruitService;
import com.dfs.vo.BarVo;
import com.dfs.vo.PageQueryVo;
import com.dfs.vo.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 水果控制器
 * </p>
 *
 * @author dfs
 * @since 2021-09-10
 */
@RestController
@RequestMapping("//fruit")
public class FruitController {

    @Autowired
    private FruitService fruitService;

    // 显示列表
    @GetMapping("/list")
    public List<Fruit> list() {
        return fruitService.list();
    }

    // 分页列表
    @GetMapping("/page/{page}/{size}")
    public IPage<Fruit> page(@PathVariable Integer page,
                             @PathVariable Integer size,
                             @RequestBody(required = false) PageQueryVo pageQueryVo){
        return fruitService.page(page,size,pageQueryVo);
    }
    // 删除
    @DeleteMapping("/del/{id}")
    public boolean del(@PathVariable("id") Integer id) {
        return fruitService.removeById(id);
    }

    // 根据id查单数据
    @GetMapping("/findById/{id}")
    public Fruit findById(@PathVariable("id") Integer id){
        return fruitService.getById(id);
    }

    // 编辑
    @PutMapping("/upd")
    public boolean upd(@RequestBody Fruit fruit) {
        return fruitService.updateById(fruit);
    }

    // 添加
    @PostMapping("/add")
    public boolean add(@RequestBody Fruit fruit){
        return fruitService.save(fruit);
    }

    // 查柱状图
    @GetMapping("/bar")
    public BarVo findBar() {
        return fruitService.findFruitBar();
    }

    // 查饼状图
    @GetMapping("/pie")
    public List<PieVo> findPie() {
        return fruitService.findFruitPie();
    }

}

